package com.wandian.news.mvvm.lifetool.birthday;

import android.os.Bundle;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.mylib.libcore.config.RouterConfig;
import com.mylib.libcore.mvvm.BaseMVVMActivity;
import com.mylib.libcore.utils.ActivityUtil;
import com.mylib.libcore.utils.ToastUtil;
import com.mylib.libcore.utils.UIUtils;
import com.wandian.news.R;
import com.wandian.news.adapter.LifeBirthDayRecycleAdapter;
import com.wandian.news.databinding.NewsActivityLifeBrithDayBinding;
import com.wandian.news.databinding.NewsActivityLifeMedicineBinding;

/**
 * @author Administrator
 * @date 2019/12/18-14:28
 * @description 菜单activity
 **/
@Route(path = RouterConfig.ROUTER_ACTIVITY_NEWS_BIRTH_DAY)
public class LifeBirthDayActivity extends BaseMVVMActivity<LifeBirthDayActivityViewModel>   {
    private NewsActivityLifeBrithDayBinding dataBinding;
    private LifeBirthDayRecycleAdapter adapter;

    @Override
    public void init(Bundle savedInstanceState) {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.news_activity_life_brith_day);
        dataBinding.setLifecycleOwner(this);
        dataBinding.setViewModel(mViewModel);
        initViewData();
        initClink();
        initRecycle();

    }

    private void initViewData(){
        ActivityUtil.getInstance().showStatusView(this,dataBinding.viewSysTop,true);
        dataBinding.bindTransparentToolBar.toolBarTvTitle.setText("生日性格");
        mViewModel.dataBean.observe(this,dataBean->{
            if(!UIUtils.isEmpty(dataBean) && !UIUtils.isEmpty(dataBean.getNewslist())){
                adapter.setNewData(dataBean.getNewslist());
            }

        });
    }

    private void initClink(){
        dataBinding.bindTransparentToolBar.toolBarIvBack.setOnClickListener(v -> finish());


        dataBinding.tvSearch.setOnClickListener(v -> {
            finishhideSoftBoard();
            if(UIUtils.isEmpty(dataBinding.etMouth.getText())){
                ToastUtil.show("请输入月份");
                return;
            }
            if(Integer.parseInt(dataBinding.etMouth.getText().toString())>12){
                ToastUtil.show("月份错误");
                return;
            }
            if(UIUtils.isEmpty(dataBinding.etDay.getText())){
                ToastUtil.show("请输入日期");
                return;
            }
            if(Integer.parseInt(dataBinding.etDay.getText().toString())>31){
                ToastUtil.show("日期错误");
                return;
            }
            mViewModel.getData(dataBinding.etMouth.getText().toString(),dataBinding.etDay.getText().toString());
        });
    }

    private void initRecycle(){
        adapter = new LifeBirthDayRecycleAdapter(R.layout.news_item_life_birth_day_style);
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
        dataBinding.recycler.setLayoutManager(layoutManager);
        dataBinding.recycler.setAdapter(adapter);
    }


    @Override
    protected void onDestroy() {
        finishhideSoftBoard();
        super.onDestroy();
    }
}
